/**
 * 
 */
package com.qiyou.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qiyou.dao.IAttendanceDao;
import com.qiyou.dao.impl.AttendanceDaoImpl;
import com.qiyou.db.IDatabase;
import com.qiyou.entity.Activity;
import com.qiyou.util.DBUtil;

/**
 * @author Administrator
 *
 */
public class AttendanceDaoProxy implements IAttendanceDao {
	private Connection conn = null;
	private IAttendanceDao attendanceDao = null;
	
	public AttendanceDaoProxy(IDatabase database){
		this.conn = database.getConnection();
		this.attendanceDao = new AttendanceDaoImpl(this.conn);
	}

	@Override
	public boolean doCreate(String userId, long acId) throws SQLException {
		if ((acId > 0) && (null != userId)) {
			try {
				return this.attendanceDao.doCreate(userId, acId);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
		}
		
		return false;
	}

	@Override
	public boolean doDelete(String userId, long acId) throws SQLException {
		if ((acId > 0) && (null != userId)) {
			try {
				return this.attendanceDao.doDelete(userId, acId);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
		}
		return false;
	}

	@Override
	public List<Activity> getUserActivities(String userId) throws SQLException {
		if (null != userId) {
			try {
				return this.attendanceDao.getUserActivities(userId);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
		}
		return null;
	}

}
